<template>
  <avue-form ref="form"
             :option="option"
             v-model="formData"
             @submit="handleSubmit">

  </avue-form>

</template>

<script>
import {reactive, toRefs} from "vue";
import {processAppConfig} from "@/util/appConfigUtil";
import {useArrangeStore} from "@/store/arrangeStore";
import pinia from "@/store/store";

const arrangeStore = useArrangeStore(pinia)
// import {processAppConfig} from "@/util/appConfigUtil";
// import _ from "lodash";
//
const appConfig = processAppConfig()

export default {
  name: "ExportPicker",
  setup(props, {emit}) {
    console.log(emit)


    const formData = reactive({
      option: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '科目',
            prop: 'subject',
            type: "select",
            multiple: true,
            row: true,
            span: 24,
            dicData: []
          },
          // {
          //   label: '校区',
          //   prop: 'campus',
          //   type: "select",
          //   multiple: true,
          //   row: true,
          //   span: 24,
          //   dicData: []
          // },
          {
            label: '文件名',
            prop: 'fileName',
            row: true,
            span: 24,
            type: "input",
          }

        ]
      },
      formData: {
        fileName: appConfig.exportConfig.fileName
      },
      props: {
        subjects: []
      }

    })

    //处理确认
    function handleSubmit() {
      console.log(formData.formData)
      console.log(arrangeStore.arrangeData);
      return formData.formData;
    }

    function openPicker(dicData) {
      console.log("openPicker")
      updateDictData(dicData)

    }

    function updateDictData(dicData) {
      let column = formData.option.column
      for (let dictDataKey in dicData) {
        let columnItem = column.find(item => item.prop === dictDataKey)
        console.log('columnItem', columnItem)
        if (columnItem) {
          columnItem.dicData = dicData[dictDataKey];
        }
      }
    }

    return {
      ...toRefs(formData),
      handleSubmit,
      openPicker

    }

  }
}
</script>

<style scoped>

</style>